package org.jeecg.modules.inventory.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.jeecg.modules.inventory.entity.Inventory;
import org.jeecg.modules.inventory.mapper.InventoryMapper;
import org.jeecg.modules.inventory.service.IInventoryService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Collections;
import java.util.List;

/**
 * @Description: 库存表
 * @Author: jeecg-boot
 * @Date:   2025-04-15
 * @Version: V1.0
 */
@Service
public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory> implements IInventoryService {

    @Override
    public Inventory getByBatchId(String batchId) {
        LambdaQueryWrapper<Inventory> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(Inventory::getBatchId,batchId);
        return getOne(wrapper);
    }

    @Override
    public List<Inventory> getByMaterialIdAndTankIdOrderByCreateTime(String materialId, String tankId) {
        LambdaQueryWrapper<Inventory> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(Inventory::getMaterialId,materialId)
                .eq(Inventory::getTankId,tankId)
                .in(Inventory::getStatus,1, 2)
                .orderByAsc(Inventory::getCreateTime);
        return list(wrapper);
    }

    @Override
    public boolean existsByBatchId(String batchId) {
        LambdaQueryWrapper<Inventory> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(Inventory::getBatchId,batchId);
        return count(wrapper) > 0;
    }

}
